home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / etc / init.d / killprocs < prev    next >
Text File  |  2008-10-14  |  1KB  |  73 lines

  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:          killprocs
  4. # Required-Start:    $local_fs
  5. # Required-Stop:
  6. # Default-Start:     1
  7. # Default-Stop:
  8. # Short-Description: executed by init(8) upon entering runlevel 1 (single).
  9. ### END INIT INFO
  10.  
  11. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  12.  
  13. . /lib/lsb/init-functions
  14.  
  15. do_start () {
  16.     # Kill all processes.
  17.     log_action_begin_msg "Asking all remaining processes to terminate"
  18.     killall5 -15 # SIGTERM
  19.     log_action_end_msg 0
  20.     alldead=""
  21.     for seq in 1 2 3 4 5 6 7 8 9 10; do
  22.         # use SIGCONT/signal 18 to check if there are
  23.         # processes left.  No need to check the exit code
  24.         # value, because either killall5 work and it make
  25.         # sense to wait for processes to die, or it fail and
  26.         # there is nothing to wait for.
  27.         
  28.         if killall5 -18 ; then
  29.             :
  30.         else
  31.             alldead=1
  32.             break
  33.         fi
  34.  
  35.         sleep 1
  36.     done
  37.     if [ -z "$alldead" ] ; then
  38.         log_action_begin_msg "Killing all remaining processes"
  39.         killall5 -9 # SIGKILL
  40.         log_action_end_msg 1
  41.     else
  42.         log_action_begin_msg "All processes ended within $seq seconds."
  43.         log_action_end_msg 0
  44.     fi
  45.  
  46.     # We start update here, since we just killed it.
  47.     if [ -x /sbin/update ] && [ "$(uname -s)" = Linux ]
  48.     then
  49.         case "$(uname -r)" in
  50.           0.*|1.*|2.[0123].*)
  51.             /sbin/update
  52.             ;;
  53.         esac
  54.     fi
  55. }
  56.  
  57. case "$1" in
  58.   start)
  59.     do_start
  60.     ;;
  61.   restart|reload|force-reload)
  62.     echo "Error: argument '$1' not supported" >&2
  63.     exit 3
  64.     ;;
  65.   stop)
  66.     # No-op
  67.     ;;
  68.   *)
  69.     echo "Usage: $0 start|stop" >&2
  70.     exit 3
  71.     ;;
  72. esac
  73.